package com.seveneight.baijiesteward.ui.main.model;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BaseEntity;
import com.seveneight.baijiesteward.bean.ShareImgBean;
import com.seveneight.baijiesteward.http.BaseModel;
import com.seveneight.baijiesteward.http.BaseObserver;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.http.RetrofitFactory;
import com.seveneight.baijiesteward.http.XObserver;
import com.seveneight.baijiesteward.ui.main.contract.ShareImgContract;
import com.seveneight.baijiesteward.utils.LogUtil;

import java.util.List;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/3/23.
 */

public class ShareImgModel extends BaseModel implements ShareImgContract.ShareImgModel {
    @Override
    public void getImgData(Context context, RequestBody body, MyCallBack<List<ShareImgBean>> myCallBack) {
        RetrofitFactory.getInstence().API().getShareImg(body).
                compose(this.<BaseEntity<AnyBean>>setThread())
                .subscribe(new XObserver<AnyBean>() {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        LogUtil.d("banklist:" + t.getData().toString());
                        if (t.getData().getSPList() != null) {
                            List<ShareImgBean> data = JSON.parseArray(t.getData().getSPList(), ShareImgBean.class);
                            myCallBack.onSuccess(data);
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }
}
